package my.jbf.firstGame.BITMAP;


import android.graphics.*;
import android.view.*;
import my.jbf.firstGame.GAMEDATA.*;
import my.jbf.firstGame.*;




public class AttackKey
{



	/*射击按钮设置*/
	private boolean isTouchDown=false;
	private boolean isShow=false;
	private  Point LeftTopPoint;
	private  Point RightBottomPoint;


	private Point CenterPoint;

	private int mTouchID=-1;
	private SharedPreferenceManager mSPM=MainActivity.mSPM;

	/*射击按钮设置完毕*/
	private Canvas mcanvas;
	private Bitmap mBitmap;
	private Paint mpaint;
	private int ButtonDownType=0;

	public AttackKey()
	{
		CenterPoint = new Point((mSPM.getAttackKeyXY().x - mSPM.getAttackKeySize()), (mSPM.getAttackKeyXY().y -  mSPM.getAttackKeySize()));
		LeftTopPoint=new Point();
		RightBottomPoint=new Point();



		mBitmap = Bitmap.createBitmap((int)(mSPM.getAttackKeySize() ), (int)(mSPM.getAttackKeySize() ), Bitmap.Config.ARGB_8888);
		mcanvas = new Canvas(mBitmap);
		mpaint = new Paint();
		mpaint.setColor(mSPM.getAttackKeyColor());
		mpaint.setStyle(Paint.Style.STROKE);
	}
	private boolean isInKey(float InSideX, float InSideY)
	{

		return (InSideX >= 0 && InSideY >= 0 && InSideX <= mSPM.getAttackKeySize() && InSideY <= mSPM.getAttackKeySize());
	}
	public boolean getShowing()
	{
		return isShow;
	}
	public void setShowing(boolean IsShow)
	{
		this.isShow=IsShow;
	}

	public boolean onTouchEvent(MotionEvent event)
	{
		boolean isUsed=false;
		switch (event.getActionMasked())
		{
			case MotionEvent.ACTION_DOWN:
				{
//					if (isInKey(event.getX() - OutSideStartPoint.x, event.getY() - OutSideStartPoint.y))
//					{
//						isTouchDown = true;
//						ButtonDownType = 1;
//						mTouchID = event.getPointerId(event.getActionIndex());
//					}
//					break;
				}
			case MotionEvent.ACTION_POINTER_DOWN:
				{

					if (isInKey(event.getX(event.getActionIndex()) - mSPM.getAttackKeyXY().x, event.getY(event.getActionIndex()) - mSPM.getAttackKeyXY().y))
					{
						isTouchDown = true;
						ButtonDownType = 1;
						mTouchID = event.getPointerId(event.getActionIndex());
						isUsed=true;
					}
					break;


				}

			case MotionEvent.ACTION_MOVE:
				{

					break;
				}
			case MotionEvent.ACTION_POINTER_UP:
				{
					if (event.getPointerId(event.getActionIndex()) == mTouchID)
					{
						isTouchDown = false;
						mTouchID = -1;
						ButtonDownType = 2;
						isUsed=true;
					}
					break;
				}
			case MotionEvent.ACTION_UP:
				{
					if (event.getPointerId(event.getActionIndex()) == mTouchID)
					{

						ButtonDownType = 2;
						isUsed=true;
					}
					isTouchDown = false;
					mTouchID = -1;


					break;
				}
			case MotionEvent.ACTION_CANCEL:
				{

				}
		}
		return isUsed;
	}
	public Bitmap getbitmap()
	{
		reDraw();
		return mBitmap;
	}
	public int getButtonDownType()
	{
		return ButtonDownType;
	}
	private void reDraw()
	{
		
		mBitmap.eraseColor(Color.argb(0,0,0,0));
		
		mcanvas.drawCircle(mSPM.getAttackKeySize()/2, mSPM.getAttackKeySize()/2, mSPM.getAttackKeySize()/2, mpaint);

	}
	public Point getCenterPoint()
	{
		return CenterPoint;
	}
	public Point getLeftTopPoint(){return LeftTopPoint;}
	public Point getRightBottomPoint(){return RightBottomPoint;}
	public void setButtonDownType(int i)
	{
		ButtonDownType = i;
	}
}
